﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Components_NewsDetail : System.Web.UI.UserControl
{
    DatabaseHelper helper;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Page.RouteData.Values["Param"] != null)
            {
                int iNewsID = Convert.ToInt32(Server.HtmlEncode(Utils.KillChars(Page.RouteData.Values["Param"].ToString())));
                loadData(iNewsID);
            }
            else  div_Title.InnerText = "<B>Không tìm thấy dữ liệu</B>";
        }
    }
    private void loadData(int iNewsID)
    {
        try
        {
            helper = new DatabaseHelper();
            System.Data.Common.DbParameter paramNewsID = helper.Parameter;
            paramNewsID.ParameterName = "NewsID";
            paramNewsID.DbType = DbType.Int32;
            paramNewsID.Value = iNewsID;
            helper.AddParameter(paramNewsID);

            System.Data.Common.DbParameter paramNewsType = helper.Parameter;
            paramNewsType.ParameterName = "NewsType";
            paramNewsType.DbType = DbType.String;
            paramNewsType.Value = "";
            helper.AddParameter(paramNewsType);

            System.Data.Common.DbParameter paramPageNumber = helper.Parameter;
            paramPageNumber.ParameterName = "PageNumber";
            paramPageNumber.DbType = DbType.Int32;
            paramPageNumber.Value = 1;
            helper.AddParameter(paramPageNumber);

            System.Data.Common.DbParameter paramPageSize = helper.Parameter;
            paramPageSize.ParameterName = "PageSize";
            paramPageSize.DbType = DbType.Int32;
            paramPageSize.Value = 100;
            helper.AddParameter(paramPageSize);
            DataTable dt = helper.ExecuteDataTable("Web_GetNews", CommandType.StoredProcedure, ConnectionState.CloseOnExit);
            if (dt.Rows.Count > 0)
            {
                div_Title.InnerText = dt.Rows[0]["Title"].ToString();
                div_Content.InnerHtml = dt.Rows[0]["Content"].ToString();  
            }
            else
            {
                div_Title.InnerText = "Không tìm thấy dữ liệu";
            }
        }
        catch (Exception ex)
        {
            ControlUtil.LogError("Promotion Page-loadData:" + ex.Message);
        }
    }
}